* Firm organization with multiple establishments
* Section III.B: Appendix Tables B.2-B.3

clear all 
set matsize 4000
set more off

capture log close
log using log/12_facts-p_MEorg_layer-firm.log, replace

use data/MEorg_2000-2010_p_layer-firm.dta, clear
count

********************************************************************************
***	Establishment/HQ-level analyses	********************************************
********************************************************************************

gen shr_mgmt_w_bet_glm = shr_mgmt_w_bet / 100
sum shr_mgmt_w_bet_glm
label variable shr_mgmt_w_bet_glm "Managerial share in wage sum, layer"

gen shr_bloss_w_bet_glm = shr_bloss_w_bet / 100
sum shr_bloss_w_bet_glm
label variable shr_bloss_w_bet_glm "Managerial share in wage sum, Blossfeld"

gen ln_prdt_wkr_2 = ln_prdt_workers * ln_prdt_workers
label variable ln_prdt_wkr_2 "Log \# non-m. employees of est., squared"

qui tab jahr, gen(d_jhr)

//	# FE: 256 (HQ: 244) wz 2008, 207 (201) wz 1993, 402 ao_kreis
global FEestHQ93	"d_est_93wz* d_ao_kreis* d_jhr*" //	d_est_wz is based on w08_3
global optSEest		"vce(cluster untid)"
global optSEHQ		"vce(cluster untid)"
global optGLM		"link(logit) family(binomial) nolog"
global opttab		"b(%9.3f) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) compress mtitles style(tex) label"

********************************************************************************
***	Descriptives ***************************************************************

*	# layers HQ vs. establishments
qui gen aux = count_mgmt_bet if hauptbet == 1
bys untid jahr: egen count_mgmt_haupt = min(aux)
drop aux

//	Share of establishments with more/same/fewer layers than headquarters
tab2 count_mgmt_bet count_mgmt_haupt if hauptbet == 0

********************************************************************************
***	Table B.13: Mg. organization of establishments and headquarters

eststo col1, title("\# layers"): qui poisson count_mgmt_bet ln_prdt_workers ldistall 	$FEestHQ93 if hauptbet == 0, $optSEest
eststo col2, title("Mg.share"):  qui glm shr_mgmt_w_bet_glm ldistall 					$FEestHQ93 if hauptbet == 0, $optGLM $optSEest
eststo col3, title("Mg.share"):  qui glm shr_bloss_w_bet_glm ldistall 					$FEestHQ93 if hauptbet == 0, $optGLM $optSEest

eststo col4, title("\# layers"): qui poisson count_mgmt_bet ln_prdt_workers max_log_dist	$FEestHQ93 if hauptbet == 1, $optSEHQ
eststo col5, title("Mg.share"):  qui glm shr_mgmt_w_bet_glm max_log_dist 					$FEestHQ93 if hauptbet == 1, $optGLM $optSEHQ
eststo col6, title("Mg.share"):  qui glm shr_bloss_w_bet_glm max_log_dist  					$FEestHQ93 if hauptbet == 1, $optGLM $optSEHQ

esttab col1 col2 col3 col4 col5 col6, ///
	$opttab se(%9.3f) indicate($FEestHQ93, label(Y N)) order(ldistall max_log_dist ln_prdt_workers) 
esttab col1 col2 col3 col4 col5 col6, ///
	$opttab p(%9.3f)  indicate($FEestHQ93, label(Y N)) order(ldistall max_log_dist ln_prdt_workers) 

********************************************************************************
***	Firm-level analyses	********************************************************
********************************************************************************

estimates clear

keep if flg_untjhr == 1
drop flg_untjhr
drop d_ao_kreis* d_est_93wz*

drop betnr w93_3_gen ao_kreis hauptbet empl_bet distance* ldist* ///
	count_mgmt_bet shr_mgmt_bet prdt_wkrs_bet ln_prdt_workers shr_mgmt_w_bet shr_mgmt_bet_bloss ///
	shr_bloss_w_bet* 

gen shr_mgmt_w_unt_glm = shr_mgmt_w_unt / 100
sum shr_mgmt_w_unt_glm
label variable shr_mgmt_w_unt_glm "Managerial share in wage sum, layer"

gen shr_bloss_w_unt_glm = shr_bloss_w_unt / 100
sum shr_bloss_w_unt_glm
label variable shr_bloss_w_unt_glm "Managerial share in wage sum, Blossfeld"

gen ln_prdt_wkr_unt_2 = ln_prdt_wkr_unt * ln_prdt_wkr_unt
label variable ln_prdt_wkr_unt_2 "Log \# non-m. employees of firm, squared"
gen ln_sales_2 = ln_sales * ln_sales
label variable ln_sales_2 "Log sales of firm, squared"

global FEunt93	"d_93wz* d_hq_kreis* d_legal* d_jhr*" // d_93wz bezieht sich auf HQ Sektor
global optSEunt	"vce(cluster untid)"

********************************************************************************
***	Table B.12: Mg. organization of firm

eststo col1, title("\# layers"): qui poisson count_mgmt_unt ln_sales max_log_dist	$FEunt93, $optSEunt
eststo col2, title("\# layers"): qui poisson count_mgmt_unt ln_sales ln_area  		$FEunt93, $optSEunt
eststo col3, title("\# layers"): qui poisson count_mgmt_unt ln_prdt_wkr_unt max_log_dist	$FEunt93, $optSEunt
eststo col4, title("\# layers"): qui poisson count_mgmt_unt ln_prdt_wkr_unt ln_area			$FEunt93, $optSEunt

eststo col5, title("Mg.share"): qui glm shr_mgmt_w_unt_glm max_log_dist 	$FEunt93, $optGLM $optSEunt
eststo col6, title("Mg.share"): qui glm shr_mgmt_w_unt_glm ln_area  		$FEunt93, $optGLM $optSEunt
eststo col7, title("Mg.share"): qui glm shr_bloss_w_unt_glm max_log_dist	$FEunt93, $optGLM $optSEunt
eststo col8, title("Mg.share"): qui glm shr_bloss_w_unt_glm ln_area			$FEunt93, $optGLM $optSEunt

esttab col1 col2 col3 col4 col5 col6 col7 col8, ///
	$opttab se(%9.3f) indicate($FEunt93, labels(Y N)) order(max_log_dist ln_area ln_sales ln_prdt_wkr_unt)
esttab col1 col2 col3 col4 col5 col6 col7 col8, ///
	$opttab p(%9.3f)  indicate($FEunt93, labels(Y N)) order(max_log_dist ln_area ln_sales ln_prdt_wkr_unt)

erase data/MEorg_2000-2010_p_layer-firm.dta

log close
